import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Scanner;


public class Update
{
	private Connection con;

	public Update(Connection c, ConnectDb d)
	{
		con = c;
		System.out.println("Enter the part number you would like to update ");
		Scanner in = new Scanner(System.in);
		String pnum = in.nextLine();

		System.out.println("Enter the new part number you would like: ");
		in = new Scanner(System.in);
		String newPnum = in.nextLine();

		//check if part number exists

		for(int i = 0; i <4; i++)
		{
			String tableName = "";
			if(i==0)
				tableName = "RDIMARS";
			else if (i==1)
				tableName = "RDIMBEH";
			else if (i==2)
				tableName = "RDIMDAN";
			else
				tableName = "RDIMMOD";
			String query = "select pnum from " + tableName + " where pnum='" + newPnum.trim() + "'";

			try
			{          
				Statement stmnt = con.createStatement();
				ResultSet rs = stmnt.executeQuery(query);
				String result = null; //only have to check if 1 thing outputed.

				while(rs.next())
					result = rs.getString(1);

				if (result != null)
				{
					updatePnum(newPnum);
				}
			}	
			catch (SQLException ex) 
			{
				System.err.println(ex.getMessage());
			}
		}
	}

	public void updatePnum(String newPnum)
	{
		String tempTableCrx = "CREATE TABLE temp_crx AS SELECT * FROM RADCRX";
		String tempTable = "Create table temp_";
		String update = "update ";
	}


}
